class Solution {
public:
    bool findNumberIn2DArray(vector<vector<int>>& matrix, int target) {
        int m = matrix.size();
        int n;
        if(m > 0){
            n = matrix[0].size();
        }
        
        int l = 0;
        int r = n-1;
        while(l >= 0 && l < m && r >= 0 && r < n){
            
            if(target == matrix[l][r]){
                return true;
            }else if(target < matrix[l][r]){
                r--;
            }else{
                l++;
            }
        }
        
        return false;
    }
};
